﻿using System;
using System.Collections.Generic;

using SportTraining.MVVM.View;

namespace SportTraining.MVVM.ViewModel.Impl
{
    public class MainWindowViewModel : ViewModelBase<MainWindowViewModel>, IMainWindowViewModel
    {
        /// <summary>
        ///  коллекция используем для передачи объектов между vm
        /// </summary>
        private readonly Dictionary<object, object> objectStore = new Dictionary<object, object>();

        #region Implementation of IMainWindowViewModel
        private Uri currentPageUri = AppUri.MainPage;

        public Uri CurrentPageUri
        {
            get { return currentPageUri; }
            set
            {
                currentPageUri = value;
                FirePropertyChanged(type => type.CurrentPageUri);
            }
        }

        public void SaveObject(object key, object value)
        {
            if (objectStore.ContainsKey(key))
            {
                objectStore[key] = value;
            }
            else
            {
                objectStore.Add(key, value);
            }
        }

        public object GetObject(object key)
        {
            if (objectStore.ContainsKey(key))
            {
                return objectStore[key];
            }

            return null;
        }

        public void DeleteObject(object key)
        {
            if (objectStore.ContainsKey(key))
            {
                objectStore.Remove(key);
            }
        }

        public void ClearDictionary()
        {
            objectStore.Clear();
        }

        #endregion
    }
}